package com.fivestar.pmanager.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fivestar.pmanager.core.base.BaseCommonParameterBean;
import com.fivestar.pmanager.core.exception.DMLNoRecordEffectedException;
import com.fivestar.pmanager.core.service.BaseServiceImpl;
import com.fivestar.pmanager.dao.mapper.SysOperationMapper;
import com.fivestar.pmanager.model.SysModuleBean;
import com.fivestar.pmanager.model.SysOperationBean;

 /**
 * 用户操作表
 * SysOperationService
 * @author 
 */
@Service("sysOperationService")
public class SysOperationService extends BaseServiceImpl<SysOperationBean>
{
	private final static Logger log = Logger.getLogger(SysOperationService.class);
	@Autowired
    private SysOperationMapper mapper;


    @Override
    public int insert(SysOperationBean smOperation, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        smOperation.initBeforeCreate(commonParam.getActorId());
        int result;
        if ((result = mapper.insert(smOperation)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return smOperation.getRowId();
    }


    @Override
    public int delete(SysOperationBean smOperation, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        smOperation.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.delete(smOperation)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }

    @Override
    public int deletePhysics(SysOperationBean smOperation, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException {
        int result;
        if ((result = mapper.deletePhysics(smOperation)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public int update(SysOperationBean smOperation, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        smOperation.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.update(smOperation)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }
    
    
    @Override
    public int updateBySelective(SysOperationBean smOperation, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        smOperation.initBeforeUpdate(commonParam.getActorId());
        int result;
        if ((result = mapper.updateBySelective(smOperation)) != 1)
        {
            throw new DMLNoRecordEffectedException();
        }
        return result;
    }


    @Override
    public List<SysOperationBean> getList(SysOperationBean smOperation)
    {
        return mapper.getList(smOperation);
    }


    @Override
    public SysOperationBean getSingleById(Integer arg0)
    {
        return mapper.getSingleById(arg0);
    }


    @Override
    public int getCountOfPage(SysOperationBean smOperation)
    {
        return mapper.getCountOfPage(smOperation);
    }


    @Override
    public List<SysOperationBean> getListOfPage(SysOperationBean smOperation)
    {
        return mapper.getListOfPage(smOperation);
    }


	@Override
    public int getCount(SysOperationBean smOperation)
    {
        return mapper.getCount(smOperation);
    }


    @Override
    public void save(SysOperationBean smOperation, BaseCommonParameterBean commonParam)
            throws DMLNoRecordEffectedException
    {
        if(smOperation.getRowId() == null)
        {
            insert(smOperation, commonParam);
        }
        else
        {
            updateBySelective(smOperation, commonParam);
        }
    }


    @Override
    public SysOperationBean getSingle(SysOperationBean smOperation)
    {
        return mapper.getSingle(smOperation);
    }

    /**
     * 获取当期页面对应的模块
     *
     * @param operationUrl 当前页面url
     */
    public SysModuleBean findModuleByOperation(String operationUrl)
    {
        return mapper.findModuleByOperation(operationUrl);
    }

}
